package model

import (
	"gorm.io/gorm"
	"week2zk-project/rpc/global"
)

//商品表

type Goods struct {
	gorm.Model
	GoodsTitle  string `gorm:"type:varchar(40);not null;"`
	GoodsImg    string `gorm:"type:varchar(255);not null;"`
	GoodsPrice  int64  `gorm:"type:int(3);not null;"`
	GoodsStock  int64  `gorm:"type:int(3);not null;"`
	SalesVolume int64  `gorm:"type:int(3);not null;comment:销量"`
	Evaluate    string `gorm:"type:varchar(50);not null;comment:评价"`
}

type Img struct {
	gorm.Model
	GoodsImg string `gorm:"type:varchar(255);not null;"`
}

func (g *Goods) Create() error {
	return global.DB.Create(&g).Error
}

func (g *Goods) Details(goodsTitle string) error {
	err := global.DB.Where("goods_title = ?", goodsTitle).First(&g).Error
	return err
}

func (g *Goods) List() error {
	return global.DB.Find(&g).Order("goods_price,desc").Error
}
